// redux2reducer就是根据action来对state进行操作，
// redux中的state是不能直接修改的，只能通过action来修改，
// 相当于我们在单例中定义setter方法。
import {
    ADD_NUMBER,
    SUB_NUMBER
  } from './constants.js';
  
  const initialState = {
    counter: 0
  }
  
  function reducer(state = initialState, action) {
    switch(action.type) {
      case ADD_NUMBER:
        return {...state, counter: state.counter + action.num};
      case SUB_NUMBER:
        return {...state, counter: state.counter - action.num};
      default:
        return state;
    } 
  }
  
  export default reducer;